import com.dinmax.flash.draw.control.Control
import com.dinmax.flash.draw.common.Point

class com.dinmax.flash.draw.utilities.Triangulo extends Control {

	private var parent:MovieClip;
	private var clip:MovieClip;
	private var point1:Point;
	private var point2:Point;
	private var point3:Point;
	private var _colors:Array; // Arrays que manipulan el relleno si es GRADIENT
	private var _alphas:Array; //
	private var _ratios:Array; //
	private var _matrix:Object; // domina el gradient
	private var _type:String; // String puede ser "linear" o "radial".
	private var _gradient:Boolean;

	private var BORDER:Number=0;
	private var BORDER_COLOR:Number=0;
	private var BORDER_ALPHA:Number=100;
	private var BG_COLOR:Number=0;
	private var BG_ALPHA:Number=100;

	private static var instanciaNumero:Number=0; 
	public static function getInstancia():String {
		instanciaNumero++;
		return "mcTri"+instanciaNumero;
	}

	function Triangulo(parent:MovieClip, point1:Point, point2:Point, point3:Point, color:Number, alpha:Number){
	this.parent=parent;
	this.point1=point1;
	this.point2=point2;
	this.point3=point3;
		if(color!=undefined){ BG_COLOR=color; BORDER_COLOR=color; }
		if(alpha!=undefined){ BG_ALPHA=alpha; BORDER_ALPHA=alpha; }

	}

	public function getClip():MovieClip{
		return clip;
	}
	
	public function setBorder(border:Number, borderColor:Number, alphaBorder:Number){
		BORDER=border;
		BORDER_COLOR=borderColor;
		BORDER_ALPHA=alphaBorder;
	}
	public function setFill(color:Number, alpha:Number){
		BG_COLOR=color;
		BG_ALPHA=alpha;
	}
	public function setGradient(colors:Array, alphas:Array, ratios:Array, grados:Number, type:String){
		_type = type; if(_type==undefined) { _type="linear";}
		_colors = colors; if(_colors==undefined) { _colors = [0xFFFFFF, 0xc8c8c8];}
		_alphas = alphas; if(_alphas==undefined) { _alphas = [100, 100];}
		_ratios = ratios; if(_ratios==undefined) { _ratios = [0xd, 0xFF];}
		var nGrados:Number = (grados/180)*Math.PI; if (nGrados==undefined) { nGrados=0;}
		_matrix = { matrixType:"box", x:0, y:0, w:getSize().getX(), h:getSize().getY(), r:nGrados }
		_gradient=true;
	}

	public function refresh(){
		draw();
	}

	public function draw(){
		var _nombre:String = getInstancia();
		if(clip==undefined){
		clip = parent.createEmptyMovieClip(_nombre, parent.getNextHighestDepth());
		} 
		clip.clear();

		if(BORDER > 0){
			clip.lineStyle(BORDER, BORDER_COLOR, BORDER_ALPHA);
		}
		if(!_gradient){
			clip.beginFill(BG_COLOR, BG_ALPHA);
		} else{
			clip.beginGradientFill(_type, _colors, _alphas, _ratios, _matrix);
		}
		clip.lineTo(point1.getX(),point1.getY());
		clip.lineTo(point2.getX(),point2.getY());
		clip.lineTo(point3.getX(),point3.getY());
		clip.lineTo(point1.getX(),point1.getY());
		clip.endFill();
		clip._x = getLocation().getX();
		clip._y = getLocation().getY();
		clip._xscale= getSize().getX()*100 /clip._width;
		clip._yscale= clip._xscale;
	
	}
}